package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.pojo.Device;
import com.example.demo.mapper.DeviceMapper;
import com.example.demo.service.DeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sjy
 * @since 2025-05-25
 */
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Override
    public List<Device> findByBoardroomId(Integer boardroomId){
        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("boardroom_id", boardroomId);
        return deviceMapper.selectList(queryWrapper);
    }

    @Override
    public List<String> getAllDeviceNames() {
        // 查询所有设备
        List<Device> devices = this.list();
        // 提取设备名称并去重
        List<String> deviceNames = devices.stream()
                .map(Device::getName) // 提取设备名称
                .distinct() // 去重
                .collect(Collectors.toList()); // 收集为列表
        return deviceNames;
    }
}
